Crate simple_asn1
source · [−]Expand description
A small ASN.1 parsing library for Rust. In particular, this library is used to translate the binary DER encoding of an ASN.1-formatted document into the core primitives of ASN.1. It is assumed that you can do what you need to from there.
The critical items for this document are the traits ToASN1
and FromASN1
.
The first takes your data type and encodes it into a Vec
of simple ASN.1
structures (ASN1Block
s). The latter inverts the process.
Items that implement ToASN1
can be used with the function der_encode
to provide single-step encoding of a data type to binary DER encoding.
Similarly, items that are FromASN
can be single-step decoded using
the helper function der_decode
.
You can implement one or both traits, depending on your needs. If you do implement both, the obvious encode/decode quickcheck property is strongly advised.
For decoding schemes that require the actual bytes associated with the
binary representation, we also provide FromASN1WithBody
. This can be
used with the offset information in the primitive ASN1Block
s to, for
example, validate signatures in X509 documents.
Finally, this library supports ASN.1 class information. I’m still not sure why it’s useful, but there it is.
Please send any bug reports, patches, and curses to the GitHub repository
at https://github.com/acw/simple_asn1
.
Macros
A handy macro for generating OIDs from a sequence of u64
s.
Structs
Enums
A primitive block from ASN.1.
An ASN.1 block class.
An error that can arise decoding ASN.1 primitive blocks.
An error that can arise encoding ASN.1 primitive blocks.
Traits
A trait defining types that can be decoded from an ASN1Block
stream.
Any member of this trait is also automatically a member of
FromASN1WithBody
, as it can obviously just ignore the body.
A trait defining types that can be decoded from an ASN1Block
stream,
assuming they also have access to the underlying bytes making up the
stream.
The set of types that can automatically converted into a sequence
of ASN1Block
s. You should probably use to_asn1() but implement
to_asn1_class(). The former has a default implementation that passes
ASN1Class::Universal
as the tag to use, which should be good for
most people.
Functions
Automatically decode a type via DER encoding, assuming that the type
is a member of FromASN1
or FromASN1WithBody
.
Automatically encode a type into binary via DER encoding, assuming
that the type is a member of ToASN1
.
Translate a binary blob into a series of ASN1Block
s, or provide an
error if it didn’t work.
Given an ASN1Block
, covert it to its DER encoding, or return an error
if something broke along the way.